# 说明 ： 串行执行多个任务 ，输出最终结果。
# 序列中的第一个runnable_1是 串行执行的，后面的runnable_2和runnable_3是并行执行的。 后面的依赖前面的结果。
from langchain_core.runnables import RunnableLambda


def add_one(x: int) -> int:
    return x + 1
def mul_two(x: int) -> int:
    return x * 2
def mul_three(x: int) -> int:
    return x * 3

runnable_1 = RunnableLambda(add_one)
runnable_2 = RunnableLambda(mul_two)
runnable_3 = RunnableLambda(mul_three)

# 写法1  自动强转为 RunnableParallel
sequence =  runnable_1 | {
    "mul_two": runnable_2,
    "mul_three": runnable_3
}

# 写法2 显式声明 RunnableParallel
# sequence = runnable_1 |  \
# RunnableParallel( {
#     "mul_two": runnable_2,
#     "mul_three": runnable_3
# })

# 写法3 内部赋值
# sequence = runnable_1 | \
#     RunnableParallel(
#         mul_two = runnable_2,
#         mul_three = runnable_3
#     )

print(sequence.invoke(1))
